#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+5,mod = 998244353;
int n,ans,a[N],b[N];
void dfs(int x,bool fl)
{
	if(x>n)
	{
		int now = 1;
		for(int i = 1;i<=n;i++) now = 1ll*now*b[i]%mod;
		if(fl) ans = (ans+now)%mod;
		return; 
	}
	for(int i = 0;i<=a[x];i++)
		b[x]+=i,b[x%n+1]+=a[x]-i,dfs(x+1,fl|(i==0)),b[x]-=i,b[x%n+1]-=a[x]-i;
}
signed main()
{
	freopen("trade.in","r",stdin);
	freopen("trade.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>n;
	bool fl = 1;
	for(int i = 1;i<=n;i++)
		cin>>a[i],fl&=(a[i]<=1);
	if(fl)
	{
		for(int i = 1;i<=n;i++)
			if(a[i]==0) return cout<<0,0;
		cout<<1;
		return 0;
	}
	else
	{
		dfs(1,0);
		cout<<ans;
	}
	return 0;
}

